package sanphone.com.runningschool.MyOrder;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import sanphone.com.runningschool.JuShou.JuShouDetailActivity;
import sanphone.com.runningschool.R;
import sanphone.com.runningschool.entity.Order;

public class AcceptListViewAdapter extends BaseAdapter {
    private List<Order>orders;
    private Context mContext;
    public AcceptListViewAdapter(Context context, List<Order> infos) {
        mContext = context;
       orders = infos;
    }


    @Override
    public int getCount() {
        return orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(orders.size()-position);
    }

    @Override
    public long getItemId(int position) {
        return orders.size()-position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
       ViewHolder holder;
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.accepted_order_item, null);
            holder.ContentText=view.findViewById(R.id.acceptorder_content);
            holder.DayText=view.findViewById(R.id.accept_day);
            holder.MonthText=view.findViewById(R.id.accept_month);
            holder.DetailText=view.findViewById(R.id.accpeted_order_detail);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        //控件和数据之间进行绑定
       final Order order=orders.get(position);

        holder.MonthText.setText(order.getCreatedTime().substring(5,7)+"月");
        holder.DayText.setText(order.getCreatedTime().substring(8,10));
        holder.ContentText.setText("物品名称："+order.getThingName()+"\n"+"物品重量："+order.getThingWeight()
                +"\n起始时间："+order.getThingTime()
                +"\n送达时间："+order.getDeliverTime()+"\n起始地址："+order.getThingPlace()+
                "\n送达地址："+order.getDeliverPlace()+"\n酬劳："+order.getMoney());
        holder.ContentText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(mContext,AcceptedOrderActivity.class);
                intent.putExtra("nickName",order.getAcceptNickName());
                intent.putExtra("thingName" ,order.getThingName());
                intent.putExtra("thingPlace",order.getThingPlace());
                intent.putExtra("deliverPlace",order.getDeliverPlace());
                intent.putExtra("deliverTime",order.getDeliverTime());
                intent.putExtra("thingTime",order.getThingTime());
                intent.putExtra("money",order.getMoney());
                intent.putExtra("detail",order.getOtherDeatil());
                intent.putExtra("thingWeight",order.getThingWeight());
                intent.putExtra("behaviorId",order.getBehaviorId());
                intent.putExtra("publisherName",order.getUserName());
                intent.putExtra("publisherPhone",order.getUserPhone());
                intent.putExtra("status",order.getStatus());
                Log.e("behaviorId", order.getBehaviorId());
                mContext.startActivity(intent);
            }
        });
        holder.DetailText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(mContext,AcceptedOrderActivity.class);
                intent.putExtra("nickName",order.getAcceptNickName());
                intent.putExtra("thingName" ,order.getThingName());
                intent.putExtra("thingPlace",order.getThingPlace());
                intent.putExtra("deliverPlace",order.getDeliverPlace());
                intent.putExtra("deliverTime",order.getDeliverTime());
                intent.putExtra("thingTime",order.getThingTime());
                intent.putExtra("money",order.getMoney());
                intent.putExtra("detail",order.getOtherDeatil());
                intent.putExtra("thingWeight",order.getThingWeight());
                intent.putExtra("behaviorId",order.getBehaviorId());
                intent.putExtra("publisherName",order.getUserName());
                intent.putExtra("publisherPhone",order.getUserPhone());
                intent.putExtra("status",order.getStatus());
                mContext.startActivity(intent);
            }
        });
        return view;
    }

    class ViewHolder {
        TextView DayText,MonthText, ContentText,DetailText;

    }
}
